<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="120px">
			<el-form-item label="档案袋编号" prop="bagNo">
				<el-input v-model="queryParams.bagNo" placeholder="请输入档案袋编号" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="档案盒编号" prop="boxNo">
				<el-input v-model="queryParams.boxNo" placeholder="请输入档案盒编号" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="档案盒条码" prop="boxBarCode">
				<el-input v-model="queryParams.boxBarCode" placeholder="请输入档案盒条码" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="档案袋条码" prop="bagCode">
				<el-input v-model="queryParams.bagCode" placeholder="请输入档案袋条码" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="袋状态" prop="bagStat">
				<el-select v-model="queryParams.bagStat" placeholder="请选择袋状态">
					<el-option v-for="dict in bag_stat" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
				</el-select>
			</el-form-item>

			<el-form-item label="用户编号" prop="custNo">
				<el-input v-model="queryParams.custNo" placeholder="请输入用户编号" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="用户名称" prop="custName">
				<el-input v-model="queryParams.custName" placeholder="请输入用户名称" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="转存标志" prop="dumpFlag">
				<el-select v-model="queryParams.dumpFlag" placeholder="请选择转存标志">
					<el-option v-for="dict in dump_flag" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
				<el-button icon="Refresh" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<!-- 	<el-col :span="1.5">
				<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['archive:ArchiveBag:add']">新增</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate" v-hasPermi="['archive:ArchiveBag:edit']">修改</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete" v-hasPermi="['archive:ArchiveBag:remove']">删除</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['archive:ArchiveBag:export']">导出</el-button>
			</el-col> -->
			<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="ArchiveBagList" @selection-change="handleSelectionChange">
			<!-- <el-table-column type="selection" width="55" align="center" /> -->
			<el-table-column label="档案袋标识" align="center" prop="bagId" width="150px" />
			<el-table-column label="档案盒标识" align="center" prop="boxId" width="150px" />
			<el-table-column label="档案袋编号" align="center" prop="bagNo" width="150px" />
			<el-table-column label="档案盒编号" align="center" prop="boxNo" width="150px" />
			<el-table-column label="档案盒条码" align="center" prop="boxBarCode" width="150px" />
			<el-table-column label="档案袋条码" align="center" prop="bagCode" width="150px" />
			<el-table-column label="袋状态" align="center" prop="bagStat">
				<template #default="scope">
					<dict-tag :options="bag_stat" :value="scope.row.bagStat" />
				</template>
			</el-table-column>
			<el-table-column label="总件数" align="center" prop="tNum" />
			<el-table-column label="已装页数" align="center" prop="pagesInNum" />
			<el-table-column label="档案室标识" align="center" prop="roomId" width="250px" />
			<el-table-column label="用户标识" align="center" prop="custId" />
			<el-table-column label="用户编号" align="center" prop="custNo" />
			<el-table-column label="用户名称" align="center" prop="custName" />
			<el-table-column label="转存标志" align="center" prop="dumpFlag" >
				<template #default="scope">
					<dict-tag :options="dump_flag" :value="scope.row.dumpFlag" />
				</template>
			</el-table-column>
			<el-table-column label="档案对象类型" align="center" prop="archObjType"  width="150px" >
				<template #default="scope">
					<dict-tag :options="arch_obj_type" :value="scope.row.archObjType" />
				</template>
			</el-table-column>
			<el-table-column label="档案类型" align="center" prop="mtrlType" width="150px">
				<template #default="scope">
					<dict-tag :options="archive_type" :value="scope.row.mtrlType" />
				</template>
			</el-table-column>

			<!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<template #default="scope">
					<el-button type="text" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['archive:ArchiveBag:edit']">修改</el-button>
					<el-button type="text" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['archive:ArchiveBag:remove']">删除</el-button>
				</template>
			</el-table-column> -->
		</el-table>

		<pagination v-show="total>0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
		 @pagination="getList" />

		<!-- 添加或修改档案袋对话框 -->
		<el-dialog :title="title" v-model="open" width="500px" append-to-body>
			<el-form ref="ArchiveBagRef" :model="form" :rules="rules" label-width="80px">
				<el-form-item label="档案袋标识" prop="boxId">
					<el-input v-model="form.boxId" placeholder="请输入档案袋标识" />
				</el-form-item>
				<el-form-item label="档案袋编号" prop="bagNo">
					<el-input v-model="form.bagNo" placeholder="请输入档案袋编号" />
				</el-form-item>
				<el-form-item label="档案盒编号" prop="boxNo">
					<el-input v-model="form.boxNo" placeholder="请输入档案盒编号" />
				</el-form-item>
				<el-form-item label="档案盒条码" prop="boxBarCode">
					<el-input v-model="form.boxBarCode" placeholder="请输入档案盒条码" />
				</el-form-item>
				<el-form-item label="档案袋条码" prop="bagCode">
					<el-input v-model="form.bagCode" placeholder="请输入档案袋条码" />
				</el-form-item>
				<el-form-item label="袋状态" prop="bagStat">
					<el-input v-model="form.bagStat" placeholder="请输入袋状态" />
				</el-form-item>
				<el-form-item label="总件数" prop="tNum">
					<el-input v-model="form.tNum" placeholder="请输入总件数" />
				</el-form-item>
				<el-form-item label="已装页数" prop="pagesInNum">
					<el-input v-model="form.pagesInNum" placeholder="请输入已装页数" />
				</el-form-item>
				<el-form-item label="档案室标识" prop="roomId">
					<el-input v-model="form.roomId" placeholder="请输入档案室标识" />
				</el-form-item>
				<el-form-item label="档案室标识" prop="custId">
					<el-input v-model="form.custId" placeholder="请输入档案室标识" />
				</el-form-item>
				<el-form-item label="用户编号" prop="custNo">
					<el-input v-model="form.custNo" placeholder="请输入用户编号" />
				</el-form-item>
				<el-form-item label="用户名称" prop="custName">
					<el-input v-model="form.custName" placeholder="请输入用户名称" />
				</el-form-item>
				<el-form-item label="转存标志" prop="dumpFlag">
					<el-input v-model="form.dumpFlag" placeholder="请输入转存标志" />
				</el-form-item>
			</el-form>
			<template #footer>
				<div class="dialog-footer">
					<el-button type="primary" @click="submitForm">确 定</el-button>
					<el-button @click="cancel">取 消</el-button>
				</div>
			</template>
		</el-dialog>
	</div>
</template>

<script setup name="ArchiveBag">
	import {
		listArchiveBag,
		getArchiveBag,
		delArchiveBag,
		addArchiveBag,
		updateArchiveBag
	} from "@/api/archive/ArchiveBag";

	const {
		proxy
	} = getCurrentInstance();


	const {
		bag_stat,
		dump_flag,
		arch_obj_type,
		archive_type
	} = proxy.useDict('bag_stat', 'dump_flag', 'arch_obj_type', 'archive_type');

	const ArchiveBagList = ref([]);
	const open = ref(false);
	const loading = ref(true);
	const showSearch = ref(true);
	const ids = ref([]);
	const single = ref(true);
	const multiple = ref(true);
	const total = ref(0);
	const title = ref("");

	const data = reactive({
		form: {},
		queryParams: {
			pageNum: 1,
			pageSize: 10,
			boxId: null,
			bagNo: null,
			boxNo: null,
			boxBarCode: null,
			bagCode: null,
			bagStat: null,
			tNum: null,
			pagesInNum: null,
			roomId: null,
			custId: null,
			custNo: null,
			custName: null,
			dumpFlag: null,
			archObjType: null,
			mtrlType: null
		},
		rules: {}
	});

	const {
		queryParams,
		form,
		rules
	} = toRefs(data);

	/** 查询档案袋列表 */
	function getList() {
		loading.value = true;
		listArchiveBag(queryParams.value).then(response => {
			ArchiveBagList.value = response.rows;
			total.value = response.total;
			loading.value = false;
		});
	}

	// 取消按钮
	function cancel() {
		open.value = false;
		reset();
	}

	// 表单重置
	function reset() {
		form.value = {
			bagId: null,
			boxId: null,
			bagNo: null,
			boxNo: null,
			boxBarCode: null,
			bagCode: null,
			bagStat: null,
			tNum: null,
			pagesInNum: null,
			roomId: null,
			custId: null,
			custNo: null,
			custName: null,
			dumpFlag: null,
			archObjType: null,
			mtrlType: null
		};
		proxy.resetForm("ArchiveBagRef");
	}

	/** 搜索按钮操作 */
	function handleQuery() {
		queryParams.value.pageNum = 1;
		getList();
	}

	/** 重置按钮操作 */
	function resetQuery() {
		proxy.resetForm("queryRef");
		handleQuery();
	}

	// 多选框选中数据
	function handleSelectionChange(selection) {
		ids.value = selection.map(item => item.bagId);
		single.value = selection.length != 1;
		multiple.value = !selection.length;
	}

	/** 新增按钮操作 */
	function handleAdd() {
		reset();
		open.value = true;
		title.value = "添加档案袋";
	}

	/** 修改按钮操作 */
	function handleUpdate(row) {
		reset();
		const bagId = row.bagId || ids.value
		getArchiveBag(bagId).then(response => {
			form.value = response.data;
			open.value = true;
			title.value = "修改档案袋";
		});
	}

	/** 提交按钮 */
	function submitForm() {
		proxy.$refs["ArchiveBagRef"].validate(valid => {
			if (valid) {
				if (form.value.bagId != null) {
					updateArchiveBag(form.value).then(response => {
						proxy.$modal.msgSuccess("修改成功");
						open.value = false;
						getList();
					});
				} else {
					addArchiveBag(form.value).then(response => {
						proxy.$modal.msgSuccess("新增成功");
						open.value = false;
						getList();
					});
				}
			}
		});
	}

	/** 删除按钮操作 */
	function handleDelete(row) {
		const bagIds = row.bagId || ids.value;
		proxy.$modal.confirm('是否确认删除档案袋编号为"' + bagIds + '"的数据项？').then(function() {
			return delArchiveBag(bagIds);
		}).then(() => {
			getList();
			proxy.$modal.msgSuccess("删除成功");
		}).catch(() => {});
	}

	/** 导出按钮操作 */
	function handleExport() {
		proxy.download('archive/ArchiveBag/export', {
			...queryParams.value
		}, `ArchiveBag_${new Date().getTime()}.xlsx`)
	}

	getList();
</script>
